Deavmi's coding shack
Commit 12d5b4a9bd21ceab095126b9953623feb19c54be
Parents : f014bd2
Author : Tristan Brice Velloza Kildaire <deavmi@redxen.eu>
Date : 2026-05-01T13:58:17+02:00
Added initial code
Changes
2 files changed, 47 insertions(+), 0 deletions(-)
Diff
diff --git a/README.md b/README.md
index e8e67e3..3304ebd 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,13 @@ The `StdLogger` in `std/logger` is most likely what you will want to be using as
has support for level-based filtering (via `LevelFilter`) and uses an `Appender` which
logs messages that show the log level, the message text and more.
+### Structured logging
+
+For structured logging support take a look at the `std/appenders/structured` which contains
+the `StructuredAppender` which will consume a `LogRecord` and then turn its key-value pairs
+into JSON key-value mappings and then write this out to a specific `io.Writer` (or standard
+output by default).
+
## Interface compatibility
The `StdLogger` is compatible with the [FreeFaces](https://pkg.go.dev/new.git.deavmi.assigned.network/deavmi/freefaces.git) [logging API](https://pkg.go.dev/new.git.deavmi.assigned.network/deavmi/freefaces.git/logging), this means
diff --git a/std/appenders/structured/core.go b/std/appenders/structured/core.go
new file mode 100644
index 0000000..0d1fc2a
--- /dev/null
+++ b/std/appenders/structured/core.go
@@ -0,0 +1,40 @@
+package structured
+
+import (
+ "fmt"
+ "io"
+ "os"
+
+ "new.git.deavmi.assigned.network/deavmi/glog.git/record"
+ "new.git.deavmi.assigned.network/deavmi/go-niknaks.git/types"
+)
+
+// an Appender which takes in the LogRecord's
+// key-value pairs and JSONifies them before
+// writing them to the provided io.Writer
+type StructuredAppender struct {
+ w io.Writer
+}
+
+// creates a new StructuredAppender that will
+// write to the provided io.Writer
+func NewWithWriter(w io.Writer) (StructuredAppender, error) {
+ if w == nil {
+ return types.Zero[StructuredAppender](), fmt.Errorf("The writer cannot be null")
+ }
+
+ return StructuredAppender{w: w}, nil
+}
+
+// creates a new StructuredAppender that will
+// write to standard output
+func New() (StructuredAppender, error) {
+ return NewWithWriter(os.Stdout)
+}
+
+func (sa StructuredAppender) Do(lr record.LogRecord) error {
+ keys := lr.Keys()
+ for _, key := range keys {
+
+ }
+}
Served by rngit 1.5.0 - Generated in 0.09s